<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../config.inc.php");

session_start();
$_LangPath = "gamescore";	//語言檔參數，務必放在最前面
include_once(__Language_Path."/selectlanguage_member.php");
include_once(__Modules_Path."/Lotto.lib.php");
include_once(__Modules_Path."/ChangeTime.lib.php");
include_once(__Common_Path."/marquee/Marquee2_".$_intLang.".php");
include_once(__Common_Path."/Lotto.inc.php");

$intLottoID = trim($_data["LottoID"]);
if(empty($intLottoID)){
	$intLottoID = (defined('__MemInitLottoID'))?__MemInitLottoID:1;
	if(empty($intLottoID))$intLottoID = 1;
}
$intLType = $_arrLotto[$intLottoID]["LType"];

//取得成績陣列
$_arrGameScore = array();
@include_once(__FCommon_Path."/GameScore".$intLottoID.".inc.php");


$_data["Page"] = intval($_data["Page"]);	//所在頁數
if($_data["Page"] <= 0)$_data["Page"] = 1;
$intTotalNum = sizeof($_arrGameScore);	 //總共多少筆記錄
$intOnePageNum = 10;	//一頁 10 筆記錄
$intTotalPage = ceil($intTotalNum / $intOnePageNum);	//共多少頁數
if($_data["Page"] > $intTotalPage)$_data["Page"] = $intTotalPage;
$intStartNum = ($_data["Page"] - 1)*$intOnePageNum;	//所在頁數開始記錄
$intEndNum = $_data["Page"]*$intOnePageNum - 1;	//所在頁數結束記錄

//if($intLottoID == 7 || $intLottoID == 8){
//	$fp = @file(__Membertemplate_Path."/gamescore".$intLType."-1.html");
//}else{
	$fp = @file(__Membertemplate_Path."/gamescore".$intLType.".html");
//}
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);
$fp = str_replace("{TP}", $intTotalPage, $fp);
$fp = str_replace("{SelfPage}", $_SERVER["PHP_SELF"], $fp);
$fp = str_replace("{Marquee}", $_Marquee, $fp);
$fp = str_replace("{LottoID}", $intLottoID, $fp);

$arrLottoPower = getLottoUsePowerArray();
foreach($_arrLotto as $intLID => $arrL){
	if(!in_array($intLID, $arrLottoPower))continue;

	$strSd = ($intLID == $intLottoID)?" selected":"";
	$strOption .= "<option value='".$intLID."'".$strSd.">".$arrL["Lotto_".$_intLang]."</option>";
}
$fp = str_replace("{SelectLottoOption}", $strOption, $fp);

preg_match("/<!--@ GameScore Start @\/\/-->(.+)<!--@ GameScore End @\/\/-->/s", $fp, $arrScore);
preg_match("/<!--@ SelectPage Start @\/\/-->(.+)<!--@ SelectPage End @\/\/-->/s", $fp, $arrCon);
$strSelect = "";
for($i = 1; $i <= $intTotalPage; $i++){
	$strTmp = str_replace("{SP}", $i, $arrCon[1]);
	$strTmp = str_replace("{SelectPage}", $i, $strTmp);
	$strTmp = str_replace("{Selected}", ($i == $_data["Page"])?"selected":"", $strTmp);
	$strSelect .= $strTmp;
}
$fp = preg_replace("/<!--@ SelectPage Start @\/\/-->.+<!--@ SelectPage End @\/\/-->/s", $strSelect, $fp);

$strScore = "";
for($i = $intStartNum; $i <= $intEndNum; $i++){
	if(!is_array($_arrGameScore[$i]))continue;
	$arrAnimals = getAnimalsParamsByDate($intLottoID, $_arrGameScore[$i]["GameDate"]);
	$arrAnimals = getExChangeAnimalsParams($arrAnimals);
	$strGameTime = TimeForm($_arrGameScore[$i]["GameDate"], $_arrGameScore[$i]["GameTime"], "Y-m-d H:i:s", "UToC");

	$intSum = 0;
	$intSN	= (int)$_arrGameScore[$i]["NumberSpecial"];
	$strTmp = str_replace("{GameNo}", sprintf("%03s", $_arrGameScore[$i]["SerialNo"]), $arrScore[1]);
	$strTmp = str_replace("{GameDate}", $strGameTime, $strTmp);
	$strTmp = str_replace("{SpBall}", sprintf("%02s", $_arrGameScore[$i]["NumberSpecial"]), $strTmp);
	$strTmp = str_replace("{ANSp}", $_arrAnimals[$arrAnimals[$_arrGameScore[$i]["NumberSpecial"]]], $strTmp);

	$arrNum = explode(",", $_arrGameScore[$i]["NumberNormal"]);
	//if(($intLottoID == 7 || $intLottoID == 8) && sizeof($arrNum) == 3)$arrNum = array("", "", $arrNum[0], $arrNum[1], $arrNum[2]);
	for($j = 0; $j < sizeof($arrNum); $j++){
		if($intLType == 1){
			$strTmp = str_replace("{Ball".($j+1)."}", sprintf("%02s", $arrNum[$j]), $strTmp);
			$strTmp = str_replace("{AN".($j+1)."}", $_arrAnimals[$arrAnimals[$arrNum[$j]]], $strTmp);
		}else{
			$strTmp = str_replace("{Ball".($j+1)."}", $arrNum[$j], $strTmp);
		}
		//if(($intLottoID == 7 || $intLottoID == 8) && $j < 2)continue;
		$intSum += $arrNum[$j];
	}
	$intSum += $intSN;
	$strTmp = str_replace("{TheSum}", (string)$intSum, $strTmp);

	if($intSN == $_arrLotto[$intLottoID]["DrawSpecial"]){
		$strSNOE = $_strSame_String[DrawSpecial]; //特碼單雙
		$strSNOU = $_strSame_String[DrawSpecial]; //特碼大小
		$strSNSOE = $_strSame_String[DrawSpecial]; //特碼大小
	}else{
		$strSNOE = ($intSN % 2 == 1?$_strSame_String[Odd]:$_strSame_String[Even]);
		$strSNOU = ($intSN >= (int)$_arrLotto[$intLottoID]["SpecialOverNumber"]?$_strSame_String[Over]:$_strSame_String[Under]);
		$strSNSOE = ((($intSN % 10 + floor($intSN / 10)) % 2 == 1)?$_strSame_String[Odd]:$_strSame_String[Even]);
	}
	$strSumOE = ($intSum % 2 == 1?$_strSame_String[Odd]:$_strSame_String[Even]);
	$strSumOU = ($intSum >= (int)$_arrLotto[$intLottoID]["NormalOverNumber"]?$_strSame_String[Over]:$_strSame_String[Under]);

	$strType = "";
	if($arrNum[0] == $arrNum[1] && $arrNum[0] == $arrNum[2])$strType = $_strGameScore["3NumSame"];
	elseif($arrNum[0] != $arrNum[1] && $arrNum[0] != $arrNum[2] && $arrNum[1] != $arrNum[2])$strType = $_strGameScore["0NumSame"];
	else $strType = $_strGameScore["2NumSame"];
	$strTmp = str_replace("{TypeV}", $strType, $strTmp);

	switch($intLType){
		case 3:
			$arrSumN = array(($arrNum[0] + $arrNum[1]), ($arrNum[0] + $arrNum[2]), ($arrNum[0] + $arrNum[3]), ($arrNum[1] + $arrNum[2]), ($arrNum[1] + $arrNum[3]), ($arrNum[2] + $arrNum[3]));

			foreach($arrSumN as $intK => $intSumN){
				$strSNOE = ($intSumN % 2 == 1)?$_strSame_String[Odd]:$_strSame_String[Even];
				$strSNOU = ($intSumN > 9)?$_strSame_String[Over]:$_strSame_String[Under];
				$strTmp = str_replace("{SumN".$intK."}", $strSNOE." ".$strSNOU, $strTmp);
			}
			break;

		default:
			//特碼單雙
			$strTmp = str_replace("{SNOE}", $strSNOE, $strTmp);
			//特碼大小
			$strTmp = str_replace("{SNOU}", $strSNOU, $strTmp);
			//特碼大小
			$strTmp = str_replace("{SNSOE}", $strSNSOE, $strTmp);
			//總和單雙
			$strTmp = str_replace("{SumOE}", $strSumOE, $strTmp);
			//總和大小
			$strTmp = str_replace("{SumOU}", $strSumOU, $strTmp);
			break;
	}

	$strScore .= $strTmp;
}
$fp = preg_replace("/<!--@ GameScore Start @\/\/-->.+<!--@ GameScore End @\/\/-->/s", $strScore, $fp);

while(list($k, $v) = each($_strGameScore)){
	$fp = str_replace("{".$k."}", $v, $fp);
}

//輸出
WebOutputHTML($fp, 1);
?>